package cn.yunhe.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cn.yunhe.model.Admin;

public class AdminDaoImpl implements IAdminDao {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;

	public Admin adminLogin(String name, String pwd) {
		conn = BaseDB.getConnection();
		Admin admin = null;

		try {
			String sql = "select * from t_admin where adminname = ? and adminpwd = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, name);
			pstmt.setString(2, pwd);

			rs = pstmt.executeQuery();

			if (rs.next()) {
				admin = new Admin();
				admin.setAdminId(rs.getInt("aid"));
				admin.setAdminName(rs.getString("adminname"));
				admin.setAdminPwd(rs.getString("adminpwd"));
				admin.setAdminFlag(rs.getInt("adminflag"));

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return admin;
	}

}
